package cn.task.part2.part1.utils;

import java.util.HashMap;
import java.util.Map;

import org.junit.Test;

/**
 * 识别字符串里面有多少元音和辅音
 * @author Administrator
 *
 */
public class IdentifyString {
	
	//用一个HashMap记录所有的元音
	private static Map<Integer,Character> vowels = new HashMap<>();
	
	private static int count_vowels = 0;
	
	private static int count_consonants = 0;
	
	private static void initVowels() {
		//a,e,i,o,u
		vowels.put(1, 'a');
		vowels.put(2, 'e');
		vowels.put(3, 'i');
		vowels.put(4, 'o');
		vowels.put(5, 'u');
	}
	
	private static void identify(String target) {
		for(int i=0;i<target.length();i++) {
			if(vowels.containsValue(target.charAt(i))) {
				count_vowels++;
			}else {
				count_consonants++;
			}
		}
	}
	
	public static int count(String target,String judge) {
		initVowels();
		identify(target);
		if(judge.equals("vowels")) {
			return count_vowels;
		}else if(judge.equals("consonants")) {
			return count_consonants;
		}
		throw new RuntimeException();
	}
	
	//每次执行完后，得将cout有关得变量置零
	public static void destory() {
		count_consonants=0;
		count_vowels = 0;
	}
}
